﻿using DevExpress.Data;
using DevExpress.XtraGrid;
using DXApplicationTangche.UC.生产计划.编排生产批.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.生产计划.编排生产批
{
    public partial class Form订单工序记录 : DevExpress.XtraEditors.XtraForm
    {
        public Form订单工序记录()
        {
            InitializeComponent();
            this.刷新();
        }

        private void simpleButton刷新_Click(object sender, EventArgs e)
        {
            this.刷新();
        }
        private void 刷新()
        {
            List<ProcessOrderQueryDTO> processOrderQueryDTOs = 编排生产批Service.getProcessExecuteView();
            List<VOProcessOrderQueryDTO> vOProcessOrderQueryDTOs展示 = new List<VOProcessOrderQueryDTO>();
            foreach(ProcessOrderQueryDTO processOrderQueryDTO in processOrderQueryDTOs)
            {
                vOProcessOrderQueryDTOs展示.Add(new VOProcessOrderQueryDTO(processOrderQueryDTO));
            }
            this.gridControl工序执行.DataSource = vOProcessOrderQueryDTOs展示;
            this.bandedGridView工序执行.RefreshData();
            this.bandedGridView工序执行.ExpandAllGroups();
            this.bandedGridView工序执行.GroupSummary.Clear();
            this.bandedGridView工序执行.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, "orderNumber", null, "(订单数量总计= {0})"), });
            this.bandedGridView工序执行.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, "stockIn", null, "(入库数量总计= {0})"), });
        }

        private void simpleButton导出excel_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出excel";
            fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.bandedGridView工序执行.ExportToXlsx(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("文件已保存至" + fileDialog.FileName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }

    public class VOProcessOrderQueryDTO
    {
        public String orderId { get; set; }
        public String orderNo { get; set; }
        public DateTime orderDate { get; set; }
        public String styleCode { get; set; }
        public String styleNameCn { get; set; }
        public String materialCode { get; set; }
        public String materialName { get; set; }
        public String styleSizeCd { get; set; }
        public String shopName { get; set; }
        public Double salePrice { get; set; }   //  零售价，吊牌价
        public Double onlineSalePrice { get; set; } //  电商零售价
        //  度量值
        public int orderNumber { get; set; }    //  （1）每个订单的数量
        public Double orderNumberPrice { get; set; } //  订单总金额
        public int caijian { get; set; }    //  （2）每个订单已裁剪但是没打水洗的数
        public Double caijianPrice { get; set; } //  每个订单已裁剪但是没打水洗的数总金额
        public int shuixi { get; set; } //  （3）每个订单已经打印出的水洗数
        public Double shuixiPrice { get; set; } //  每个订单已经打印出的水洗数总金额
        public int unCheck { get; set; }    //  （4）待检查的数量
        public Double unCheckPrice { get; set; } //  待检查总金额
        public int unFinishChek { get; set; }   //  （5）待成品检查数量
        public Double unFinishChekPrice { get; set; } //  待成品检查总金额
        public int unStockIn { get; set; }  //  （6）已完成质检未入库数量
        public Double unStockInPrice { get; set; } //  已完成质检未入库总金额
        public int stockIn { get; set; }    //  （7）已入库数量 ——入库数量
        public Double stockInPrice { get; set; } //  入库总金额
        public VOProcessOrderQueryDTO()
        {

        }
        public VOProcessOrderQueryDTO(ProcessOrderQueryDTO processOrderQueryDTO)
        {
            this.orderId = processOrderQueryDTO.orderId;
            this.orderNo = processOrderQueryDTO.orderNo;
            this.orderDate = processOrderQueryDTO.orderDate;
            this.styleCode = processOrderQueryDTO.styleCode;
            this.styleNameCn = processOrderQueryDTO.styleNameCn;
            this.materialCode = processOrderQueryDTO.materialCode;
            this.materialName = processOrderQueryDTO.materialName;
            this.styleSizeCd = processOrderQueryDTO.styleSizeCd;
            this.shopName = processOrderQueryDTO.shopName;
            this.salePrice = processOrderQueryDTO.salePrice;
            this.onlineSalePrice = processOrderQueryDTO.onlineSalePrice;
            //工序度量值
            this.orderNumber = processOrderQueryDTO.orderNumber;
            this.orderNumberPrice = processOrderQueryDTO.orderNumber * processOrderQueryDTO.onlineSalePrice;
            this.caijian = processOrderQueryDTO.caijian;
            this.caijianPrice = processOrderQueryDTO.caijian * processOrderQueryDTO.onlineSalePrice;
            this.shuixi = processOrderQueryDTO.shuixi;
            this.shuixiPrice = processOrderQueryDTO.shuixi * processOrderQueryDTO.onlineSalePrice;
            this.unCheck = processOrderQueryDTO.unCheck;
            this.unCheckPrice = processOrderQueryDTO.unCheck * processOrderQueryDTO.onlineSalePrice;
            this.unFinishChek = processOrderQueryDTO.unFinishChek;
            this.unFinishChekPrice = processOrderQueryDTO.unFinishChek * processOrderQueryDTO.onlineSalePrice;
            this.unStockIn = processOrderQueryDTO.unStockIn;
            this.unStockInPrice = processOrderQueryDTO.unStockIn * processOrderQueryDTO.onlineSalePrice;
            this.stockIn = processOrderQueryDTO.stockIn;
            this.stockInPrice = processOrderQueryDTO.stockIn * processOrderQueryDTO.onlineSalePrice;
        }
    }
}
